package com.lineage.data.npc.quest;

import com.lineage.data.cmd.CreateNewItem;
import com.lineage.data.executor.NpcExecutor;
import com.lineage.data.quest.DragonKnightLv50_1;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Character;
import com.lineage.server.serverpackets.S_CloseList;
import com.lineage.server.serverpackets.S_NPCTalkReturn;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Npc_RedSoul extends NpcExecutor {
  private static final Log _log = LogFactory.getLog(Npc_RedSoul.class);
  
  public static NpcExecutor get() {
    return new Npc_RedSoul();
  }
  
  public int type() {
    return 3;
  }
  
  public void talk(L1PcInstance pc, L1NpcInstance npc) {
    try {
      if (!pc.isCrown())
        if (pc.isKnight()) {
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "redsoul_f4"));
        } else if (pc.isElf()) {
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "redsoul_f4"));
        } else if (pc.isWizard()) {
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "redsoul_f4"));
        } else if (pc.isDarkelf()) {
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "redsoul_f4"));
        } else if (pc.isDragonKnight()) {
          if (pc.getQuest().isStart(DragonKnightLv50_1.QUEST.get_id())) {
            switch (pc.getQuest().get_step(DragonKnightLv50_1.QUEST.get_id())) {
              case 2:
                pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "redsoul_f1"));
                return;
              case 3:
                pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "redsoul_f2"));
                return;
            } 
            pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "redsoul_f4"));
          } else {
            pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "redsoul_f4"));
          } 
        } else if (pc.isIllusionist()) {
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "redsoul_f4"));
        } else {
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "redsoul_f4"));
        }  
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void action(L1PcInstance pc, L1NpcInstance npc, String cmd, long amount) {
    if (pc.isDragonKnight())
      if (pc.getQuest().isStart(DragonKnightLv50_1.QUEST.get_id())) {
        switch (pc.getQuest().get_step(DragonKnightLv50_1.QUEST.get_id())) {
          case 2:
          case 3:
            if (cmd.equalsIgnoreCase("a")) {
              L1ItemInstance item = pc.getInventory().checkItemX(49229, 10L);
              if (item != null) {
                pc.getInventory().removeItem(item, 10L);
                pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "redsoul_f2"));
                pc.getQuest().set_step(DragonKnightLv50_1.QUEST.get_id(), 3);
                CreateNewItem.getQuestItem((L1Character)pc, npc, 49207, 1L);
                CreateNewItem.getQuestItem((L1Character)pc, npc, 49227, 1L);
              } else {
                pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "redsoul_f3"));
              } 
            } 
            return;
        } 
        pc.sendPackets((ServerBasePacket)new S_CloseList(pc.getId()));
      } else {
        pc.sendPackets((ServerBasePacket)new S_CloseList(pc.getId()));
      }  
  }
}
